<?php
include "header.php";
include "./lib/func.php";
include "./lib/config.php";

if (($user = isLogin()) == false){
    header("location:index.php");
}

/**
 * 微博关注
 * following 我的关注  followed 关注我的
 * [示例]
 * aid关注bid
 * following 关注表  following:aid(bid)
 * followed  被关注表 followed:bid(aid)
 *
 * 1.获取地址栏的u参数用户名
 * 2，查询UID
 * 3，查询UID是否在我的following[我的关注表]里
 */

$getuser = trim(getGet('u'));
$redis = connentRedis(Config::REDISHOST, Config::PORT);
$key = 'user:username:'. $getuser. ':userid';
$proId = $redis->get($key);
if (!$proId){
    showError('非法用户,用户名不存在');
    exit;
}
$isFollowing = $redis->sIsMember('following:'. $user['userid'], $proId);
$isFollowingStatus = $isFollowing ? 0 : 1;
$isFollowingWord = $isFollowing ? '取消关注' : '关注Ta';


?>
<a href="/"><img style="border:none" src="logo.png" width="192" height="85" alt="Retwis"></a>
<div id="navbar">
<a href="index.php">主页</a>
| <a href="timeline.php">热点</a>
| <a href="logout.php">退出</a>
</div>
</div>
<h2 class="username"><?php echo 'test' ?></h2>
<a href="follow.php?uid=<?php echo $proId; ?>&f=<?php echo $isFollowingStatus; ?>" class="button"><?php echo $isFollowingWord; ?></a>

<div class="post">
<a class="username" href="profile.php?u=test"></a>
world<br>
<i>11 分钟前 通过 web发布</i>
</div>

<div class="post">
<a class="username" href="profile.php?u=test">test</a>
hello<br>
<i>22 分钟前 通过 web发布</i>
</div>

<?php include "footer.php"; ?>
